''''''

# Standard
# Related
import lx
# Local
import mosh.generic_utilities


_eval = lx.eval
_layerservice = lx.Service('layerservice')
_layerservice_query = _layerservice.query
_layerservice_select = _layerservice.select

def get_all_vmap_indices(limit_to_type=None):
    '''Get all the vertex map indices, with the option of limiting it to
    map types.'''
    _layerservice_select('vmaps', 'all')

    map_indices = mosh.generic_utilities.convert_strings_to_ints(
        _layerservice_query('vmaps'))

    if map_indices is None:
        return []
    elif limit_to_type is None:
        return map_indices
    else:
        limited_map_indices = []

        for map_index in map_indices:
            if get_vmap_type(str(map_index)) == limit_to_type:
                limited_map_indices.append(map_index)

        return limited_map_indices

def get_vmap_name(vmap_index):
    '''Get the vertex map type of the supplied vmap index.
    '''
    _layerservice_select('vmap.name', str(vmap_index))

    return _layerservice_query('vmap.name')

def get_vmap_type(vmap_index):
    '''Get the vertex map type of the supplied vmap index.
    '''
    _layerservice_select('vmap.type', str(vmap_index))

    return _layerservice_query('vmap.type')

def is_vmap_selected(vmap_index):
    '''Checks whether the vmap index is selected in the vmap list.'''
    _layerservice_select('vmap.selected', str(vmap_index))

    # Alright, "not not" is far from pythonic, but i can't help using it.. 
    # it makes me giggle. :P
    return not not _layerservice_query('vmap.selected')

def get_selected_vmap_indices(limit_to_type=None):
    '''Get all the vertex map indices, with the option of limiting it to
    map types.'''
    _layerservice_select('vmaps', 'selected')

    map_indices = mosh.generic_utilities.convert_strings_to_ints(
        _layerservice_query('vmaps'))

    if map_indices is None:
        return []
    elif limit_to_type is None:
        return map_indices
    else:
        limited_map_indices = []

        for map_index in map_indices:
            if get_vmap_type(str(map_index)) == limit_to_type:
                limited_map_indices.append(map_index)

        return limited_map_indices
